package com.cdm.forum.controller;

import com.cdm.forum.common.Result;
import com.cdm.forum.dao.BoardMapper;
import com.cdm.forum.model.Board;
import com.cdm.forum.service.impl.BoardServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "板块接口")
@RestController
@RequestMapping("/board")
@Slf4j
public class BoardController {

    @Autowired
    private BoardServiceImpl boardService;

    //从配置文件里面读取值，如果没有配置，默认值为9
    @Value("${forum.index.board:9}")
    private Integer indexNum;

    /**
     * 获取主页导航栏板块数
     * @return
     */
    @ApiOperation("获取主页导航栏")
    @GetMapping("/getTopList")
    private Result<List<Board>> getTopList() {
        log.info("板块数为" + indexNum);
        List<Board> boards = boardService.selectByNum(indexNum);
        if (boards == null || boards.size() == 0) {
            boards = new ArrayList<>();
        }
        return Result.success(boards);
    }
}
